<?php
$imgName = "obraz1.jpg";
$tempDir = "./temp/";

if(isSet($_GET['angle'])){
  $angle = $_GET['angle'];
  if(!is_numeric($angle)){
    die("error\nNieprawidowe dane.");
  }

  if(!($img = imagecreatefromjpeg($imgName))){
    die("error\nBrak dostpu do obrazu.");
  }

  $white = imagecolorallocate($img, 255, 255, 255);
  $img = imagerotate($img, $angle, $white);

  $imgName = microtime().rand();
  imagejpeg($img, $tempDir.$imgName);
  imagedestroy($img);
  echo $imgName;
}
else{
  if(!($img = imagecreatefromjpeg($imgName))){
    exit();
  }
  header('Content-Type: image/jpeg');
  imagejpeg($img);
  imagedestroy($img);
}
?>
